package com.atguigu.java.ai.langchain4j.service.impl;

import com.atguigu.java.ai.langchain4j.entity.po.Doctor;
import com.atguigu.java.ai.langchain4j.mapper.DoctorMapper;
import com.atguigu.java.ai.langchain4j.service.DoctorService;
import com.atguigu.java.ai.langchain4j.utils.Result;
import com.atguigu.java.ai.langchain4j.utils.Results;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 医生信息表(Doctor)表服务实现类
 *
 * @author makejava
 * @since 2025-08-02 00:39:50
 */
@Service("doctorService")
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor> implements DoctorService {
    @Resource
    private DoctorMapper doctorMapper;


    @Override
    public Result queryNumberSource(String date, String deptName, String doctorName) {
        LambdaQueryWrapper<Doctor> doctorLambdaQueryWrapper = new LambdaQueryWrapper<>();
        doctorLambdaQueryWrapper.eq(Doctor::getScheduleDate, date);
        doctorLambdaQueryWrapper.eq(Doctor::getDeptName, deptName);
        doctorLambdaQueryWrapper.eq(Doctor::getDoctorName, doctorName);
        Doctor doctor = doctorMapper.selectOne(doctorLambdaQueryWrapper);
        if (doctor == null) {
            return Results.failure("1","该医生暂时未有排班信息！");
        }
        return Results.success(doctor);
    }

    @Override
    public Result queryNumberSourceWithoutDoctor(String date, String deptName) {
        LambdaQueryWrapper<Doctor> doctorLambdaQueryWrapper = new LambdaQueryWrapper<>();
        doctorLambdaQueryWrapper.eq(Doctor::getScheduleDate, date);
        doctorLambdaQueryWrapper.eq(Doctor::getDeptName, deptName);
        List<Doctor> doctorList = doctorMapper.selectList(doctorLambdaQueryWrapper);
        if (CollectionUtils.isEmpty(doctorList)){
            return Results.failure("1","该科室暂时未有排班信息！");
        }
        return Results.success(doctorList);
    }
}
